package __Goquery

import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"log"
)

func main() {
	url := "https://gorm.io/zh_CN/docs/"
	//Document表示要爬取的文档
	dom, err := goquery.NewDocument(url)
	if err != nil {
		log.Fatalln("访问失败", err)
	}
	dom.Find(".sidebar-link").Each(func(i int, s *goquery.Selection) {
		href, _ := s.Attr("href")
		//text := s.Text()
		doc, _ := goquery.NewDocument(url + href)
		title := doc.Find("h1.article-title").Text()
		content, _ := doc.Find(".article").Html()
		fmt.Println(i, title, content)
	})
}
